package team2.game.crow;

import org.anddev.andengine.entity.primitive.Rectangle;
import org.anddev.andengine.util.Debug;

public class HealthBar extends Rectangle {

	// ===========================================================
    // Constants
    // ===========================================================
	
	// ===========================================================
    // Fields
    // ===========================================================
    private float maxHeight;
    private float currentHeight;
    private int maxHealth;
	// ===========================================================
    // Constructors
    // ===========================================================
	
	public HealthBar(float pX, float pY, float pWidth, float pHeight, int maxHealth) {
		super(pX, pY, pWidth, pHeight);
		this.setColor(1, 0, 0);
		this.maxHeight = pHeight;
		this.currentHeight = pHeight;
		this.maxHealth = maxHealth;
	}

    // ===========================================================
    // Getter & Setter
    // ===========================================================
		
    // ===========================================================
    // Methods for/from SuperClass/Interfaces
    // ===========================================================
	
	// ===========================================================
    // Methods
    // ===========================================================
	
	public void takeDamage(int amount){
		this.currentHeight -= ((float)amount/maxHealth)*maxHeight;
		Debug.d("Current Health: "+currentHeight);
		if(currentHeight > 0)
			this.setHeight(currentHeight);
		else
			this.setHeight(0);
	}
	
	public void healDamage(int amount){
		this.currentHeight += ((float)amount/maxHealth)*maxHeight;
		if(currentHeight < maxHeight)
			this.setHeight(currentHeight);
		else
			this.setHeight(maxHeight);
	}
	
	public void reset(){
		this.setHeight(maxHeight); 
	}
	
	// ===========================================================
    // Inner and Anonymous Classes
    // ===========================================================
	
}
